home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / host / RCS / Host_ByName.c,v < prev    next >
Encoding:
Text File  |  1988-06-30  |  2.1 KB  |  98 lines

  1. head     1.1;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 1.1
  9. date     88.06.30.11.06.43;  author ouster;  state Exp;
  10. branches ;
  11. next     ;
  12.  
  13.  
  14. desc
  15. @@
  16.  
  17.  
  18.  
  19. 1.1
  20. log
  21. @Initial revision
  22. @
  23. text
  24. @/* 
  25.  * Host_ByName.c --
  26.  *
  27.  *    Source code for the Host_ByName library procedure.
  28.  *
  29.  * Copyright 1988 Regents of the University of California
  30.  * Permission to use, copy, modify, and distribute this
  31.  * software and its documentation for any purpose and without
  32.  * fee is hereby granted, provided that the above copyright
  33.  * notice appear in all copies.  The University of California
  34.  * makes no representations about the suitability of this
  35.  * software for any purpose.  It is provided "as is" without
  36.  * express or implied warranty.
  37.  */
  38.  
  39. #ifndef lint
  40. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  41. #endif not lint
  42.  
  43. #include <stdio.h>
  44. #include <host.h>
  45. #include <hostInt.h>
  46. #include <string.h>
  47.  
  48.  
  49. /*
  50.  *-----------------------------------------------------------------------
  51.  *
  52.  * Host_ByName --
  53.  *
  54.  *    Return information about a host based on its name. The name may
  55.  *    be either the official name of a host or an alias for it.
  56.  *
  57.  * Results:
  58.  *    A Host_Entry pointer describing the host, or NULL if no such host
  59.  *    exists in the current database.  The Host_Entry is statically
  60.  *    allocated, and may be modified on the next call to any Host_
  61.  *    procedure.
  62.  *
  63.  * Side Effects:
  64.  *    The host file is opened if it wasn't already.
  65.  *
  66.  *-----------------------------------------------------------------------
  67.  */
  68.  
  69. Host_Entry *
  70. Host_ByName(name)
  71.     register char     *name;      /* Name of host to find */
  72. {
  73.     register Host_Entry    *entry;        /* Current entry */
  74.     register char     **cpp;        /* Pointer to alias table */
  75.  
  76.     if (Host_Start() != 0) {
  77.     return ((Host_Entry *)NULL);
  78.     }
  79.     
  80.     while (1) {
  81.     entry = Host_Next();
  82.     if (entry != (Host_Entry *)NULL) {
  83.         if (strcmp(entry->name, name) == 0) {
  84.         return (entry);
  85.         } else {
  86.         for (cpp = entry->aliases; *cpp != (char *)NULL; cpp++) {
  87.             if (strcmp(*cpp, name) == 0) {
  88.             return (entry);
  89.             }
  90.         }
  91.         }
  92.     } else {
  93.         return (Host_Entry *) NULL;
  94.     }
  95.     }
  96. }
  97. @
  98.